package com.xxx.modules.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxx.modules.entity.College;
import com.xxx.modules.entity.User;
import com.xxx.modules.mapper.AdjustMapper;
import com.xxx.modules.entity.Adjust;
import com.xxx.modules.mapper.CollegeMapper;
import com.xxx.modules.mapper.UserMapper;
import com.xxx.modules.service.AdjustService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.Arrays;
import com.xxx.modules.utils.TimeUtil;

/**
 * adjust
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2023-04-29
 */
@Service
public class AdjustServiceImpl extends ServiceImpl<AdjustMapper, Adjust> implements AdjustService {

    @Autowired
    private AdjustMapper adjustMapper;


    @Override
    public PageInfo<Adjust> selectAdjustInfo(Adjust adjust, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<Adjust> wrapper = new QueryWrapper<>();
        List<Adjust> data = adjustMapper.selectListInfo(adjust);
        return new PageInfo<>(data);
    }

    @Override
    public void saveAdjustInfo(Adjust adjust) {
        adjust.setUpdateTime(TimeUtil.getCurrentTime());
        adjustMapper.insert(adjust);
    }

    @Override
    public void updateAdjustInfo(Adjust adjust) {
        adjust.setUpdateTime(TimeUtil.getCurrentTime());
        adjustMapper.updateById(adjust);
    }

    @Override
    public void delAdjustInfo(Integer id) {
        adjustMapper.deleteById(id);
    }

    @Override
    public void delBatchAdjustInfo(String idList) {
        List<String> list = Arrays.asList(idList.split(","));
        adjustMapper.deleteBatchIds(list);
    }

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private CollegeMapper collegeMapper;
    @Override
    public PageInfo<Adjust> selectAdjustInfo2(Adjust adjust, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);//表示查询结果从第几页开始，以及每页查询多少条记录
        QueryWrapper<Adjust> wrapper = new QueryWrapper<>();//设置条件选择器
        User user = userMapper.selectById(adjust.getUserId());
        College college = collegeMapper.selectById(user.getCollegeId());
        adjust.setCollegeType(college.getType());
        adjust.setSubjectId(user.getSubjectId());
        List<Adjust> data = adjustMapper.selectListInfo(adjust);
        return new PageInfo<>(data);
    }


}